package cn.knightzz.controller;


import cn.knightzz.entity.JsonResult;
import cn.knightzz.entity.SysPopulationType;
import cn.knightzz.service.SysPopulationTypeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author knightzz
 * @since 2021-05-09
 */
@RestController
public class SysPopulationTypeController {

    @Resource
    SysPopulationTypeService populationTypeService;

    @PostMapping("/population-type")
    public JsonResult<Object> addPopulationTypeInfo(@RequestBody SysPopulationType populationType) {
        Boolean status = populationTypeService.addPopulationType(populationType);
        if (status) {
            return new JsonResult<Object>("200", "添加成功");
        } else {
            return new JsonResult<Object>("201", "添加失败");
        }
    }

    @PutMapping("/population-type")
    public JsonResult<Object> editPopulationTypeInfo(@RequestBody SysPopulationType populationType) {
        Boolean status = populationTypeService.updatePopulationType(populationType);
        if (status) {
            return new JsonResult<Object>("200", "更新成功");
        } else {
            return new JsonResult<Object>("201", "更新失败");
        }
    }

    @DeleteMapping("/population-type/{id}")
    public JsonResult<Object> deletePopulationTypeInfo(@PathVariable Long id) {
        Boolean status = populationTypeService.deletePopulationType(id);
        if (status) {
            return new JsonResult<Object>("200", "更新成功");
        } else {
            return new JsonResult<Object>("201", "更新失败");
        }
    }

    @GetMapping("/population-type")
    public JsonResult<List<SysPopulationType>> getAllPopulationTypeList() {
        List<SysPopulationType>  populationTypeList = populationTypeService.getAllPopulationTypeList();
        JsonResult<List<SysPopulationType>> result = new JsonResult<>("200" , "查询成功!");
        result.setData(populationTypeList);
        return  result;
    }
}

